package com.four.reimbursemanage.service.impl;

import com.four.reimbursemanage.common.bean.Page;
import com.four.reimbursemanage.dao.DailyapplyMapper;
import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.service.IDailyapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 日常报销申请Service业务层处理
 * 
 * @author lwy
 * @date 2024-09-18
 */
@Service
public class DailyapplyServiceImpl implements IDailyapplyService
{
    @Autowired
    private DailyapplyMapper dailyapplyMapper;

    /**
     * 查询日常报销申请
     * 
     * @param id 日常报销申请主键
     * @return 日常报销申请
     */
    @Override
    public Dailyapply selectDailyapplyById(Integer id)
    {
        return dailyapplyMapper.selectDailyapplyById(id);
    }

    @Override
    public List<Dailyapply> selectByNum(String number) {
        return dailyapplyMapper.selectByNum(number);
    }


    /**
     * 查询日常报销申请列表
     * @return 日常报销申请
     */

    @Override
    public Page<Dailyapply> getOnrePage(int pageNum, int pageSize, Date writedate, String department, String reason, String money, String rill, Integer state) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Dailyapply> list=dailyapplyMapper.selectDailyapplyList(start,pageSize,writedate, department, reason, money, rill, state);
        //获取总条目数
        int total=dailyapplyMapper.countDailyapply(writedate, department, reason, money, rill, state);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Dailyapply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    /*查询本人申请*/
    @Override
    public Page<Dailyapply> getOnrePageUser(int pageNum, int pageSize, Date writedate, String department, String reason, String money, String rill, Integer state, String number) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Dailyapply> list=dailyapplyMapper.selectByN(start,pageSize,writedate, department, reason, money, rill, state, number);
        //获取总条目数
        int total=dailyapplyMapper.countUser(writedate, department, reason, money, rill, state, number);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Dailyapply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }


    /**
     * 新增日常报销申请
     * 
     * @param dailyapply 日常报销申请
     * @return 结果
     */
    @Override
    public boolean insertDailyapply(Dailyapply dailyapply)
    {
        if (dailyapply == null){
            return false;
        }
        return dailyapplyMapper.insertDailyapply(dailyapply)>0;
    }

    /**
     * 修改日常报销申请
     * 
     * @param dailyapply 日常报销申请
     * @return 结果
     */
    @Override
    public boolean updateDailyapply(Dailyapply dailyapply)
    {
        if (dailyapply == null) {
            return false;
        }
        return dailyapplyMapper.updateDailyapply(dailyapply)>0;
    }

    @Override
    public boolean updateC(Dailyapply dailyapply) {
        if (dailyapply == null) {
            return false;
        }
        dailyapply.setState(3);
        return dailyapplyMapper.updateStateById(dailyapply)>0;
    }

    /**
     * 批量删除日常报销申请
     * 
     * @param ids 需要删除的日常报销申请主键
     * @return 结果
     */
    @Override
    public int deleteDailyapplyByIds(Integer[] ids)
    {
        return dailyapplyMapper.deleteDailyapplyByIds(ids);
    }

    /**
     * 删除日常报销申请信息
     * 
     * @param id 日常报销申请主键
     * @return 结果
     */
    @Override
    public int deleteDailyapplyById(Integer id)
    {
        return dailyapplyMapper.deleteDailyapplyById(id);
    }
}
